#!/usr/bin/env python
# -*- coding: utf8 -*-
#-------------------------------------------------------------------------------
# Name:        module1
# Purpose:
#
# Author:      iori
#
# Created:     21-02-2014
# Copyright:   (c) iori 2014
# Licence:     <your licence>
#-------------------------------------------------------------------------------

from Tkinter import *
import Image, ImageTk
import os
from Queue import Queue
from StringIO import StringIO
from threading import Thread

from utils import random_string
from verify import VerifyFrame
from jd import jd_register


def worker(q, vf):
    def get_vcode(data):
        vf.update_image(data)
        item = q.get()
        q.task_done()
        return item
    while True:
        name = random_string(6)
        pwd = random_string(8)
        jd_register(name, pwd, get_vcode)

def main():
    root = Tk()
    q = Queue()
    def enter_key(event):
        ent = event.widget
        val = ent.get()
        q.put(val)
        ent.delete(0, END)
    vf = VerifyFrame(root, fn=enter_key)
    Thread(target=worker, args=(q, vf)).start()
    root.mainloop()
    pass

if __name__ == '__main__':
    main()
